<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${package_name}.dao.${table_name}Dao">
	<sql id="selectId">
		a.id,
	<#if model_column?exists>
        <#list model_column as model>
		a.${model.columnName} AS "${model.changeColumnName}",
        </#list>
    </#if>
		a.delflag
	</sql>
	<sql id="join">
	</sql>
	<!-- **********************************************查询操作************************************** -->
	<select id="getAll" resultType="${table_name}">
		select
		<include refid="selectId" />
		from ${table_name_small} a 
		<include refid="join" />
		where a.delflag=0
	</select>
	
	<select id="getAllCommon" resultType="${table_name}">
		select
		<include refid="selectId" />
		from ${table_name_small} a 
		<include refid="join" />
		where a.delflag=0
	</select>

	<select id="getById" resultType="${table_name}">
		select
		<include refid="selectId" />
		from ${table_name_small} a 
		<include refid="join" />
		where a.delflag=0 and a.id=${r'#{id}'}
	</select>

	<select id="getmaxId" resultType="int">
		select max(a.id) from ${table_name_small} a
		<include refid="join" />
		where a.delflag=0
	</select>

	<select id="findCount" resultType="Integer">
		select count(a.id) from ${table_name_small} a 
		<include refid="join" />
		where a.delflag=0
	</select>

	<select id="findList" resultType="${table_name}">
		select
		<include refid="selectId" />
		from ${table_name_small} a
		<include refid="join" />
		where a.delflag=0
		<if test="qo.sidx!=null and qo.sidx!=''">
			order by ${r'${qo.sidx}'} ${r'${qo.sord}'}
		</if>
		limit ${r'#{first}'},${r'#{max}'}
	</select>

	<!-- **********************************************保存操作************************************** -->
	<insert id="save">
		insert into ${table_name_small}(
		    id,
		<#if model_column?exists>
			<#list model_column as model>
			${model.columnName},
			</#list>
		</#if>
			createDate,
			createUserId
		)values(
		   ${r'#{id}'},
		<#if model_column?exists>
			<#list model_column as model>
			 ${model.inupColumnName},
			</#list>
		</#if>
			${r'#{createDate}'},
			${r'#{createUserId}'}
		)
	</insert>

	<!-- **********************************************删除操作************************************** -->
	<delete id="delete">
		update ${table_name_small} set delflag=1 where
		id=${r'#{id}'}
	</delete>

	<!-- **********************************************修改操作************************************** -->
	<update id="update">
		update ${table_name_small} set
		<#if model_column?exists>
			<#list model_column as model>
			${model.columnName}=${model.inupColumnName},
			</#list>
		</#if>
		    updateDate=${r'#{updateDate}'},
		    updateUserId=${r'#{updateUserId}'}
		where id=${r'#{id}'}
	</update>
</mapper>